﻿using NB.MGJ.Common.MVC;
using NB.MGJ.Model;
using NB.MGJ.Service.AntiFake;
using NB.MGJ.Service.Origins;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NB.MGJ.Web.Controllers
{
    public class OriginsSearchController : BaseController
    {
        public QueryStatisticsService _qsService=new QueryStatisticsService();
        public OriginsSearchService _qsearch = new OriginsSearchService();
        public ActionResult CodeLogList_V()
        {
            return View();
        }

        public JsonResult PageLists(string Search, int pageIndex = 1, int pageSize = 10)
        {
            var modal = _qsService.Enterparise(LogOnUser.EnterpriseId);
            var getcode = _qsService.search(LogOnUser.EnterpriseId);
            //判断表是否纯在
            var HasForm = _qsService.HasFormService(getcode);
            if (HasForm == 0)
            {
                var res = "";
                return Json(res);
            }
            PagerModel pm = new PagerModel();
            pm.Page = pageIndex;
            pm.PageSize = pageSize;

            if (LogOnUser.Distributor != 0)
            {
                pm.StrCondition = " and ChangeLoginID=" + LogOnUser.UserID;
            }
            else
            {
                if (LogOnUser.EnterpriseId != 1)
                {
                    if (string.IsNullOrEmpty(LogOnUser.JuniorEnterprise))
                    {
                        pm.StrCondition = "  EnterpriseId  in (0)";
                    }
                    else
                    {

              
                        pm.StrCondition += " EnterpriseId=" + modal.ID + "";
                    }
                }
                else { pm.StrCondition = " 1=1  "; }
            }
            pm.StrCondition += " and Valid=1 and Fw_SCode like '%" + Search + "%'";

            var model = _qsearch.GetQueryCodeService(ref pm, modal.Code);
            return Json(model);
        }





        
	}
}